<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="box">
        <my-input :type="'text'" title="用户名" v-model="uname"></my-input>
        <my-input :type="'password'" title="密码" v-model="upwd"></my-input>
        <my-input :type="'number'" title="年龄" v-model="age"></my-input>
        <button @click="getSerialize">提交</button>
    </div>
    <script>
        const bus = new Vue();
        Vue.component("myInput",{
            template:`
                <div>
                    <label>{{title}}:</label>
                    <input :type="type" v-model="val" @input="sendVal"/>
                </div>
            `,
            props:["type","title"],
            data(){
                return{
                    val:""
                }
            },
            methods:{
                sendVal(){
                    this.$emit("input",this.val)
                }
            }
        })
        const vm = new Vue({
            el:"#box",
            data:{
                uname:'',
                upwd:'',
                age:0 
            },
            methods:{
                getSerialize(){
                    console.log(this.uname,this.upwd,this.age);
                } 
            },
        })
    </script>
</body>
</html>